package cn.neusoft.controller;


import cn.neusoft.exception.AppException;
import cn.neusoft.exception.AppExceptionCodeMsg;
import cn.neusoft.pojo.Permission;
import cn.neusoft.query.PermissionQuery;
import cn.neusoft.service.IPermissionService;
import cn.neusoft.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hxj
 * @since 2024-12-18
 */
@Api(description = "权限管理")
@RestController
@RequestMapping("/permission")
public class PermissionController extends BaseController<Permission, PermissionQuery>{

    @Autowired
    IPermissionService permissionService;

    @ApiOperation("通过角色Id查询对应权限")
    @PostMapping("/role/{roleId}")
    public ResultBean selectByRoleId(@PathVariable("roleId") Long roleId ){
        if(roleId==null || roleId==0){
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }
        PermissionQuery permissionQuery = new PermissionQuery();
        permissionQuery.setRoleId(roleId);
        List<Permission> permissions = permissionService.list(permissionQuery.getJoinWrapper());
        return ResultBean.SUCCESS(permissions);
    }

}
